package com.woniu.service.util;


import com.aliyun.dysmsapi20170525.Client;
import com.aliyun.dysmsapi20170525.models.SendBatchSmsRequest;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;


import java.util.Map;

public class Sample {

    /**
     * 使用AK&SK初始化账号Client
     *
     * @param accessKeyId
     * @param accessKeySecret
     * @return Client
     * @throws Exception
     */
    public static Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        com.aliyun.teaopenapi.models.Config config = new com.aliyun.teaopenapi.models.Config()
                // 必填，您的 AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 必填，您的 AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    //    public static void main(String[] args) throws Exception {
//        com.aliyun.dysmsapi20170525.Client client = createClient("LTAI5tGW94SLVva2e9gen9S2", "IuBvmirlU5pEAxYBt5uIPYrfsO73jL");
//        com.aliyun.dysmsapi20170525.models.SendSmsRequest sendSmsRequest = new com.aliyun.dysmsapi20170525.models.SendSmsRequest()
//                .setSignName("阿里云短信测试")
//                .setTemplateCode("SMS_154950909")
//                .setPhoneNumbers("13386103372")
//                .setTemplateParam("{\"code\":\"4321\"}");
//        com.aliyun.teautil.models.RuntimeOptions runtime = new com.aliyun.teautil.models.RuntimeOptions();
//        try {
//            // 复制代码运行请自行打印 API 的返回值
//            client.sendSmsWithOptions(sendSmsRequest, runtime);
//        } catch (TeaException error) {
//            // 如有需要，请打印 error
//            com.aliyun.teautil.Common.assertAsString(error.message);
//        } catch (Exception _error) {
//            TeaException error = new TeaException(_error.getMessage(), _error);
//            // 如有需要，请打印 error
//            com.aliyun.teautil.Common.assertAsString(error.message);
//        }
//    }
    public static void sendCode(Map<String, String> map) throws Exception {
        Client client = createClient("LTAI5tGW94SLVva2e9gen9S2", "IuBvmirlU5pEAxYBt5uIPYrfsO73jL");

        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setSignName("蜗牛实验室")
                .setTemplateCode("SMS_275070198")
                .setPhoneNumbers(map.get("phone"))
                .setTemplateParam("{\"code\":\""+map.get("code")+"\"}");
        client.sendSms(sendSmsRequest);
//        try {
//            // 复制代码运行请自行打印 API 的返回值

//        } catch (TeaException error) {
//            // 如有需要，请打印 error
//            com.aliyun.teautil.Common.assertAsString(error.message);
//        } catch (Exception _error) {
//            TeaException error = new TeaException(_error.getMessage(), _error);
//            // 如有需要，请打印 error
//            com.aliyun.teautil.Common.assertAsString(error.message);
//        }
    }
}
